#ifndef EMIXEDDER_H
#define EMIXEDDER_H

#if DIM == 2

#include "Core/RowSparse.h"
#include "FiniteDiff/MixedDer.h"
#include "Embedded/EmbeddedGrid.h"

class EMixedDer : public MixedDer
{
public:
  enum { Dim = 2 };
  enum { fitOrder = 5 };
  using BaseClass = MixedDer;
  using iVec = Vec<int, Dim>;
  using rVec = Vec<Real, Dim>;
  using EmGrid = EmbeddedGrid<Dim>;

  struct MixedDerTransform;

  EMixedDer(const EmGrid &aGrid, const Vec<Real, 3> &aA);

  void apply(const Tensor<Real, Dim> &aData, Tensor<Real, Dim> &outData) const;

  void apply(const Tensor<Real, Dim> &aData, const Tensor<Real, Dim> &rhs, Tensor<Real, Dim> &rsd) const;

  const RowSparse<iVec> &getSparseOp() const { return matOp; }

protected:
  const EmGrid     &emGrid;
  RowSparse<iVec>  matOp;
  const Real       dangerousCN = 1e4; // give a level-1 warning if the condition number is larger than this.
};

#else
//#warning "EMixedDer is omitted for 3D. "
#endif // DIM == 2

#endif //EMIXEDDER_H
